home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 40
/
Amiga Format CD40 (1999-05-11)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-06].iso
/
-readerstuff-
/
paul_qureshi
/
source
/
water1.lzx
/
waterasm.asm
< prev
Wrap
Assembly Source File
|
1981-09-11
|
3KB
|
137 lines
;--------------------------------------
; Water
;
; (C) 1995 Kimmo Roimela
;
; You may use this code for your own
; productions as you wish, but partial
; credit would be appreciated...
;--------------------------------------
ideal
p386
model small,C
codeseg
public wave
extrn C buffer3_SEG : word
extrn C VGA_SEG : word
;-----------------------------------------------
; wave
;
proc C wave far
arg DestSEG:word, SrcSEG:word, BlockX:word, BlockY:word, BlockWidth:word, BlockHeight:word
push eax ; Store the registers used.
push ebx
push edx
push cx
push si
push di
push ds
push es
push fs
push gs
; Set up the registers:
mov si,[BlockY] ; Make di point to the correct location
mov di,si ; in buffer & video memory:
shl di,8 ; Multiply by 320...
shl si,6
add di,si
add di,[BlockX] ; ...and add the initial offset.
mov cx,di ; cx always points to the end of the
add cx,[BlockWidth] ; line being drawn.
mov si,[BlockHeight] ; si counts scanlines left to draw.
shr si,1
; Set up the segment registers:
mov ds,[DestSEG] ; ds -> destination buffer
mov es,[SrcSEG] ; es -> source buffer
mov fs,[buffer3_SEG] ; fs -> velocity buffer
mov gs,[VGA_SEG] ; gs -> video memory
loop1:
; Calculate the average of the surrounding points.
mov eax,0
mov ebx,0
mov ax,[word ptr es:di-640] ; Sum the surrounding points.
add ebx,eax
mov ax,[word ptr es:di-2]
add ebx,eax
mov ax,[word ptr es:di+2]
add ebx,eax
mov ax,[word ptr es:di+640]
add ebx,eax
sar ebx,2 ; Divide. ebx now contains the average.
; Calculate the harmonic force caused by the difference between
; the current position and the average.
mov ax,[word ptr es:di]
sub ebx,eax
add ebx,8 ; Round up, or the thing sort of collapses...
sar ebx,4
; Modify the velocity accordingly & calculate the new position.
movsx edx,[word ptr fs:di] ; Get the current velocity.
; mov dx,[word ptr fs:di] ; Use this if you remove the
; damping below...
mov eax,edx ; Apply damping factor.
sal edx,9
sub edx,eax
add edx,256
sar edx,9
add dx,bx ; Modify with the force.
mov [fs:di],dx
mov bx,[word ptr es:di] ; Update the position.
add bx,dx
mov [ds:di],bx ; Write to destination buffer.
mov bl,bh ; Write to video memory.
mov [gs:di],bx
mov [gs:di+320],bx
add di,2 ; Check whether we're done.
cmp di,cx
jne loop1
sub di,[BlockWidth] ; Move on to the next scanline.
add di,640
add cx,640
dec si
jne loop1 ; All done?
pop gs
pop fs ; Restore the registers.
pop es
pop ds
pop di
pop si
pop cx
pop edx
pop ebx
pop eax
ret
endp wave
END